package com.md.sockettest.socketv1;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Author Gong
 * @Description
 * @dATE 2022/3/30 14:57
 **/
public class TestInetAddr {
    public static void main(String[] args) {
        try {
            InetAddress inet = InetAddress.getByName("www.baidu.com");
            System.out.println(inet);
            System.out.println(inet.getHostName());//域名
            System.out.println(inet.getHostAddress());//ip

            InetAddress inet1 = InetAddress.getLocalHost();//本主机
            System.out.println(inet1);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
